﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.U2D;
using UnityEngine.UI;
using Zenject;

public class DifficultySelectUI : MonoBehaviour, IPointerEnterHandler
{
    public Difficulty _difficulty { get; private set; }
    [Header("头像")] [SerializeField] private Image avatarImage;
    [SerializeField] private Image avatarBgImage;
    [Inject] private SpriteAtlas difficultyIcons;
    [Inject] private GameManager _gameManager;


    /**
     * 初始化单元格、保存对应role数据
     */
    public void InitUI(Difficulty difficulty)
    {
        _difficulty = difficulty;
        avatarImage.sprite = difficultyIcons.GetSprite(difficulty.name);
        //通过十六进制字符串
        avatarBgImage.color = ColorHexUtility.HexToColor(difficulty.bgColor);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        UpdateDifficultyInfoUI();
    }

    public void UpdateDifficultyInfoUI()
    {
        DifficultySelectUIManager.Instance.UpdateDifficultyInfoUI(_difficulty);
    }

    public void SelectDifficulty()
    {
        //记录当前选择的weapon
        _gameManager.currentDifficultyBaseData = _difficulty;
        Debug.Log("当前选择的角色：" + _gameManager.currentRoleBaseData.name);
        Debug.Log("当前选择的武器：" + _gameManager.currentWeaponsBaseData[0].name);
        Debug.Log("当前选择的难度：" + _gameManager.currentDifficultyBaseData.name);
        // 进入战斗场景
        SceneManager.LoadScene("03_GamePlay");
    }
}